home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1992-11-18 | 42.6 KB | 1,199 lines | [ TEXT/MPS ]
C.S.M.P. Digest Sun, 29 Mar 92 Volume 1 : Issue 35 Today's Topics: subclassing TWindow (was Re: Closing windows in MacApp) limit to resource file size? MacApp 3.0 and the book "C++ Programming with MacApp" Responder Mac C++ copying a resource How do you get SFGetFile() to show *.sic only How to store data record in file that grows dynamically? The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly. These digests are available (by using FTP, account anonymous, your email address as password) in the pub/mac/csmp-digest directory on ftp.cs.uoregon. edu. This is also the home of the comp.sys.mac.programmer Frequently Asked Questions list. These digests are also available via email. Just send a note saying that you want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will automatically receive each new digest as it is created. The articles in these digests are taken directly from comp.sys.mac.programmer. They are not edited; all articles included in this digest are in their original posted form. The only articles that are -not- included in these digests are those which didn't receive any replies (except those that give information rather than ask a question). All replies to each article are concatenated onto the original article in the order in which they were received. Article threads are not added to the digests until the last article added to the thread is at least one month old (this is to ensure that the thread is dead before adding it to the digests). Send administrative mail to mkelly@cs.uoregon.edu. ------------------------------------------------------- From: mlanett@void.ncsa.uiuc.edu (Mark Lanett) Subject: subclassing TWindow (was Re: Closing windows in MacApp) Organization: University of Illinois at Urbana Date: Tue, 25 Feb 1992 06:17:24 GMT keith@Apple.COM (Keith Rollin) writes: >In article <kaas.698564808@vincent1.iastate.edu> kaas@iastate.edu (Gerald E Kaas) writes: >>I was wondering if there was a way to detect if the user has closed a window >>that I opened without overriding TWindow or a TView. >Mark Lannett has posted some handy tips here, but I just wanted to ask >a follow-up question: What's wrong with sub-classing TWindow? From my >memory of MacApp and from the way you ask your question, it seems that >sub-classing TWindow is the right thing. If so, why don't you want to >do that? Nasty, nasty, nasty. I've had too many situation where I've had/wanted to subclass TWindow, and you can only subclass it once. For instance: I have *way* too many menus and need to have them appear only when the appropriate window is in front. How to do this? Subclass TWindow and have it put up/take down the window when it gets Activate true/false events*. But... In other cases I want the window to resize to fit the data it holds. So here's another TWindow subclass with a FitToData routine. Of course neither of these work with floating windows, so I have to create equivalent subclasses of TFloatWindow *also*. Subclassing TWindow causes too many problems; it's much better to stay clear. *Of course the (in)famous Mac Toolbox "I don't queue Activate events" bug crops up here: If a window is open (window A) and someone takes an action causing a document to be created which has TWO windows (B and C) then: B opens, generating a deactivate for A and an activate for itself. Then C opens, generating a deactivate for B and an activate for itself (C). Bit these aren't queued, so A's deactivate and B's activate are lost, with the result that A gets NO deactivate (why's that menu STILL in the menu bar?), B gets a deactivate WITHOUT having gotten an activate, and C actually does gets its activate. Wonderfull. I modified TWindow::Show to call gApplication->PollToolboxEvent(false) to collect the stupid activates before they get lost but that caused a mess in and of itself so I gave up on using TWindow for the job. What MacApp *really* needs is a way to inform everyone in the target chain -- not just the actual target -- when they're entering and leaving. This way my document can take care of putting up and taking down the menus, or maybe a view or view behavior can do it rather than TWindow. In fact I've already put this into my version of MacApp and it works to the extent that MacApp 3.0 targeting works (which is better than the Toolbox's queuing of activates, but not much). I suppose I should mail the MacApp 3 group and try to get them to put it in the real version... An amusing and unrelated note: Some time back I posted a ProgressDialog class to the net. I received almost no feedback and so forgot about it. So imagine my surprise when reading the ObjectMaster review in FrameWorks and seeing my ProgressDialog in an ObjectMaster view class window! Well, at least someone is using it, though I never expected to find out that way. Does this mean I've been published :-)? -- Mark Lanett mlanett@uiuc.edu Software Tools Group, NCSA, University of Illinois at Urbana-Champaign --------------------------- From: janee@ima.isc.com (Jane Eisenstein) Subject: limit to resource file size? Date: 28 Jan 92 15:09:09 GMT Organization: Interactive Systems, Cambridge, MA 02138-5302 I'm running into trouble creating large resource files. I'm dealing with large chunks of data as purgeable resources written to a temporary file. It seems that if the file becomes too large it becomes corrupted. This appears to consistently happen as the file grows from 13MB to 17MB. I'm aware that there is a limit to the number of resources in a file. Is there a limit to the total size of the resource fork? Jane Eisenstein janee@ima.isc.com - ------------------------- From: keith@Apple.COM (Keith Rollin) Subject: limit to resource file size? Date: 28 Jan 92 23:47:14 GMT Organization: Apple Computer Inc., Cupertino, CA In article <1992Jan28.150909.16199@ima.isc.com> janee@ima.isc.com (Jane Eisenstein) writes: >I'm running into trouble creating large resource files. I'm dealing >with large chunks of data as purgeable resources written to a >temporary file. It seems that if the file becomes too large it >becomes corrupted. This appears to consistently happen as the file >grows from 13MB to 17MB. I'm aware that there is a limit to the >number of resources in a file. Is there a limit to the total size of >the resource fork? Yep, and its around 16Meg. The reason for this is because the resource fork format uses 24-bit offsets internally. Take a look at the latter part of Chapter 5 of IM I to see this. -- - ---------------------------------------------------------------------------- Keith Rollin --- <Taligent .signature under construction> Disclaimer: Pretty soon, I really _won't_ be speaking for Apple... - ------------------------- From: wysocki@husc.harvard.edu (Chris Wysocki) Subject: limit to resource file size? Date: 28 Jan 92 23:12:38 GMT Organization: Harvard University, Cambridge, MA In article <1992Jan28.150909.16199@ima.isc.com>, janee@ima.isc.com (Jane Eisenstein) writes: > I'm running into trouble creating large resource files. I'm dealing > with large chunks of data as purgeable resources written to a > temporary file. It seems that if the file becomes too large it > becomes corrupted. This appears to consistently happen as the file > grows from 13MB to 17MB. I'm aware that there is a limit to the > number of resources in a file. Is there a limit to the total size of > the resource fork? Resource files are limited to 16 MB, since offsets in the resource map are only 24 bits long; see IM I-130. Chris Wysocki wysocki@husc.harvard.edu - ------------------------- From: Greg@AppleLink.Apple.Com (Greg Marriott) Subject: limit to resource file size? Date: 31 Jan 92 01:28:09 GMT Organization: Apple Computer, Inc. In article <1992Jan28.150909.16199@ima.isc.com>, janee@ima.isc.com (Jane Eisenstein) writes: > > [...] as the file grows from 13MB to 17MB. [...] Is there a limit to the total > size of the resource fork? Yes. The limit is 16MB. Offsets in the resource map are 24 bits long, which makes the maximum offset 16MB. Greg Marriott Blue Meanie Apple Computer, Inc. - ------------------------- From: keith@Apple.COM (Keith Rollin) Subject: limit to resource file size? Date: 28 Jan 92 23:47:14 GMT Organization: Apple Computer Inc., Cupertino, CA In article <1992Jan28.150909.16199@ima.isc.com> janee@ima.isc.com (Jane Eisenstein) writes: >I'm running into trouble creating large resource files. I'm dealing >with large chunks of data as purgeable resources written to a >temporary file. It seems that if the file becomes too large it >becomes corrupted. This appears to consistently happen as the file >grows from 13MB to 17MB. I'm aware that there is a limit to the >number of resources in a file. Is there a limit to the total size of >the resource fork? Yep, and its around 16Meg. The reason for this is because the resource fork format uses 24-bit offsets internally. Take a look at the latter part of Chapter 5 of IM I to see this. -- - ---------------------------------------------------------------------------- Keith Rollin --- <Taligent .signature under construction> Disclaimer: Pretty soon, I really _won't_ be speaking for Apple... - ------------------------- From: Greg@AppleLink.Apple.Com (Greg Marriott) Subject: limit to resource file size? Date: 31 Jan 92 01:28:09 GMT Organization: Apple Computer, Inc. In article <1992Jan28.150909.16199@ima.isc.com>, janee@ima.isc.com (Jane Eisenstein) writes: > > [...] as the file grows from 13MB to 17MB. [...] Is there a limit to the total > size of the resource fork? Yes. The limit is 16MB. Offsets in the resource map are 24 bits long, which makes the maximum offset 16MB. Greg Marriott Blue Meanie Apple Computer, Inc. --------------------------- From: quesnel@ems (Rene Quesnel) Subject: MacApp 3.0 and the book "C++ Programming with MacApp" Date: 17 Feb 92 13:50:31 GMT Organization: Faculty of Music, McGill University I recently bought the book "C++ Programming with MacApp" by Wilson, Rosenstein, and Shaffer. Then I read in the news that MacApp 3.0 was rewritten in C++ and that hierarchies of classes were modified (I don't know to what extent). It this book still worth reading for someone who wants to learn how to program with MacApp 3.0? Thanks, Rene Quesnel quesnel@music.mcgill.ca - ------------------------- From: ksand@apple.com (Kent Sandvik) Subject: MacApp 3.0 and the book "C++ Programming with MacApp" Date: 20 Feb 92 01:03:41 GMT Organization: MacDTS Mongols In article <1992Feb17.135031.15093@thunder.mcrcim.mcgill.edu>, quesnel@ems (Rene Quesnel) writes: > > I recently bought the book "C++ Programming with MacApp" by Wilson, > Rosenstein, and Shaffer. Then I read in the news that MacApp 3.0 > was rewritten in C++ and that hierarchies of classes were modified > (I don't know to what extent). It this book still worth reading for > someone who wants to learn how to program with MacApp 3.0? It is true that the book has samples based on MacApp 2.0. However I would purchase the book, because it gives a good overall insight into the world of MacApp and OOP programming. And it's not hard to translate the information over to the new APIs in MacApp 3.0. Kent Sandvik/DTS - ------------------------- From: michael@otago.ac.nz Subject: MacApp3 & C++ Date: 25 Feb 92 22:54:07 GMT Organization: University of Otago, Dunedin, New Zealand In article <63170@apple.Apple.COM>, keith@Apple.COM (Keith Rollin) writes: > MacApp 3.0 is written entirely in C++, and will most likely stay that > way. This means that if the pre-compiled libraries that come with > MacApp are not sufficient for you and you need to compile your own > version, you will need C++. However, you can still write your own code > in MPW Pascal if you want; it will link with MacApp just fine. This is indeed good news: I was getting discouraged about upgrading to 3.0 because of the cost of buying C and C++. However, am I correct in thinking that a reading knowledge of C++ is going to be necessary because we still occasionally have to read the source code to find out what MacApp is doing? Michael(tm) Hamel, Computing Services Centre, University of Otago, New Zealand SCULLET (n.) The last teaspoon in the washing up. - ------------------------- From: mcmath@csb1.nlm.nih.gov (Chuck McMath) Subject: MacApp3 & C++ Date: 26 Feb 92 13:11:51 GMT Organization: MSD In article <1992Feb26.115407.2225@otago.ac.nz>, michael@otago.ac.nz writes: > > > (stuff about not needing C++ to program in MacApp) > > This is indeed good news: I was getting discouraged about upgrading to 3.0 > because of the cost of buying C and C++. However, am I correct in thinking that > a reading knowledge of C++ is going to be necessary because we still > occasionally have to read the source code to find out what MacApp is doing? > > Michael(tm) Hamel, Computing Services Centre, University of Otago, New Zealand > > SCULLET (n.) > The last teaspoon in the washing up. > > While it's true you don't ABSOLUTELY need C++ to work with MacApp, you will need to have all the library permutations you need pre-built, since you wouldn't be able to -Autobuild them as needed. In addition, this obviously means you can't tweak with the MacApp source code to fix bugs (which happens once in a while). The cost to buy all the pieces is quite a lot, but it seems a necessary expense. You do need a reading knowledge of C++ to understand what's going on. In my experience the only problem you might have is in adjusting to iteration over TLists and the like. MacApp 3.0 uses iterators, which looks confusing but is not too difficult to get used to. chuck --chuck mcmath- mcmath@csb1.nlm.nih.gov MSD, Inc. * National Library of Medicine * National Institutes of Health Bethesda, MD 20894 - ------------------------- From: u_banzai@mcl.mcl.ucsb.edu (Buckaroo Banzai) Subject: MacApp3 & C++ Date: 28 Feb 92 00:15:34 GMT So, when IS MacApp 3.0 coming out?????? Anyone know? -- = Marc Tamsky u_banzai@mcl.ucsb.edu 2121dtam@ucsbuxa.ucsb.edu KB6JWE = - ------------------------- From: anders@verity.com (Anders Wallgren) Subject: MPW questions Organization: Verity, Inc., Mountain View, CA Date: Thu, 27 Feb 92 21:24:00 GMT In article <33784@nntpd.lkg.dec.com>, long@mcntsh (Rich Long) writes: > > I'm new to MPW (3.2), so I'd appreciate some help with some weird things I > can't figure out. > > 1. How do I tell the Find command to look for a tab character? find /<opt-d>t/ "the window" # <opt-d> means press option-d > > 3. What would be the script syntax for walking a directory and extracting the > file name portion of the path? For example, if I have a > "RCL:this:that:something else" path, and want the "something else" name into > a variable, how could I do this? > if "foo:bar:something else" =~ /[a-zA-Z:_0-9]<opt-x>:([a-zA-Z_0-9]<opt-x>)<opt-r>1/ set variable "{<opt-r>1}" end --------------------------- From: liran@bimacs.BITNET (Eshel Liran) Subject: Responder Date: 17 Feb 92 13:40:52 GMT Organization: Math & CS, BarIlan U, Ramat-Gan, Israel 1st Question: - ---------- Is it possible to identify the responder's socket ? Is there something unique about its address or its EntityName ? If there is nothing else i wil just have to compare the ObjStr with the computer names strings (that's what i want to avoid). 2nd Question: - ---------- What's the latest version of responder ? The one i have doesn't know the new macs (LC,SI,Classic). ........................................................................... Liran Eshel Bar-Ilan University Ramat-Gan, ISRAEL liran@bimacs.cs.biu.ac.il - ------------------------- From: woody@ucscb.UCSC.EDU (Bill Woodcock) Subject: Responder Date: 17 Feb 92 18:49:34 GMT Organization: University of California, Santa Cruz > liran@bimacs.BITNET (Eshel Liran) writes: > Is it possible to identify the responder's socket ? > Is there something unique about its address or its EntityName ? Well, on my own network here, all the Responders are using socket 253. In all likelyhood, that's just coincidence. They probably just go for the higest unused socket they can find. Also, if you hit them with an ATP ALO transaction request with data "00 00 00 01" they spit back one end-of-message transaction response full of gestalt calls or whatever. > What's the latest version of responder ? > The one i have doesn't know the new macs (LC,SI,Classic). The most recent version I see here is Responder 201. Keep in mind that Responder is now built into the System file under System 7.x. It also has a "feature" which allows people to crash your machine remotely, which makes it particularly annoying that it's now harder to remove. Disclaimer: I'm not a programmer, so I probably don't know what I'm talking about, anyhow. :-) -Bill Woodcock ________________________________________________________________________________ bill.woodcock.iv..woody@ucscb.ucsc.edu..2355.virginia.st..berkeley.ca.94709.1315 - ------------------------- From: cremer@apple.com ($mike cremer) Subject: Responder Date: 23 Feb 92 23:44:52 GMT Organization: apple computer, inc. In article <28752@darkstar.ucsc.edu>, woody@ucscb.UCSC.EDU (Bill Woodcock) writes: > > [ questions about Responder ] > > Well, on my own network here, all the Responders are using socket 253. > In all likelyhood, that's just coincidence. They probably just go for > the higest unused socket they can find. Actually, it opens a dynamic ATP socket. The code for opening a dynamic socket goes for the first "unused" socket number, starting at the top. It is pure coincidence that all appear to have the same socket. > Also, if you hit them with an > ATP ALO transaction request with data "00 00 00 01" they spit back one > end-of-message transaction response full of gestalt calls or whatever. Responder uses an un-published protocol to return system information. Apple hasn't published the protocol because they intend to replace it with something better and more reliable. DO NOT rely on either the transport or the data, as it will likely change. > The most recent version I see here is Responder 201. Keep in mind > that Responder is now built into the System file under System 7.x. The most recent version is Responder 2.0.3. It is built into the stacks for 7.x, but AppleTalk v 57.0.1 includes the new INIT version for System 6.x. > It also has a "feature" which allows people to crash your machine > remotely, which makes it particularly annoying that it's now harder to > remove. This bug was fixed as of Responder 2.0.1. Try installing the latest Responder, using the Network Software Installer 1.1 (available via anonymous FTP from ftp.apple.com in the directory /dts/mac/sys.soft/netcomm/ file net-soft-install-1-1-image.hqx). $mike cremer cremer@apple.com disclaimers To Get The Latest AppleTalk Stacks: Version: 57.0.1, for BOTH System 6.x and System 7.x Where: ftp.apple.com How: anonymous FTP directory: /dts/mac/sys.soft/netcomm/ file: net-soft-install-1-1-image.hqx --------------------------- From: Thad.Humphries@p950.f70.n109.z1.FidoNet.Org (Thad Humphries) Subject: Mac C++ Date: 18 Feb 92 20:28:00 EST I know that both Apple and Zortech have C++ compilers for MPW. But what version? APDA says MPW C++ 3.1 but is that just to match the MPW version number? SUN C++ version 2.1 is by AT&T (*that* should be current but templates and exceptions are reserved words not yet implemented) and Borland just released 3.0 (which has templates and exceptions). What's the story on the Mac? Does Apple or Zortech support templates and/or exceptions yet? * Origin: Quis custodiet ipsos custodes? (1:109/70.950) - ------------------------- From: neeri@iis.ethz.ch (Matthias Ulrich Neeracher) Subject: Mac C++ Date: 20 Feb 92 19:15:12 GMT Organization: Integrated Systems Laboratory, ETH, Zurich In article <698562057.1@blkcat.FidoNet> Thad.Humphries@p950.f70.n109.z1.FidoNet.Org (Thad Humphries) writes: >I know that both Apple and Zortech have C++ compilers for MPW. But what version? APDA says MPW C++ 3.1 but is that just to match the MPW version number? SUN C++ version 2.1 is by AT&T (*that* should be current but templates and exceptions are reserved words not yet implemented) and Borland just released 3.0 (which has templates and exceptions). > >What's the story on the Mac? Does Apple or Zortech support templates and/or exceptions yet? Apple's C++ 3.x is really just the version number matched to MPW. It is actually based on CFront 2.1, I think. It doesn't support templates or exceptions. I don't know about Zortech. Matthias BTW, consider using the return key sometimes. It is probably located above your right shift key. - --- Matthias Neeracher neeri@iis.ethz.ch `We say "gestalt" when things combine to act in ways we can't explain' -- Marvin Minsky, _The Society Of Mind_ - ------------------------- From: bbs.metalmac@tsoft.sf-bay.org (Tom Santos) Subject: Mac C++ Date: 20 Feb 92 11:37:39 GMT Organization: The TeleSoft BBS and Public Access Unix, +1 415 969 7958 Thad.Humphries@p950.f70.n109.z1.FidoNet.Org (Thad Humphries) writes: > I know that both Apple and Zortech have C++ compilers for MPW. But what vers > > What's the story on the Mac? Does Apple or Zortech support templates and/or Apple's C++ does not support any of that yet. Apple is using 2.x right now. Zortech doesn't support it either as far as I know... Tom -- Tom Santos (bbs.metalmac@tsoft.sf-bay.org) - ------------------------- From: barczejj@ss2.wpafb.af.mil (Jeff J Barczewski 52824) Subject: Mac C++ Date: 20 Feb 92 20:32:25 GMT Organization: Air Force Institute of Technology Thad.Humphries@p950.f70.n109.z1.FidoNet.Org (Thad Humphries) writes: >I know that both Apple and Zortech have C++ compilers for MPW. But what version? APDA says MPW C++ 3.1 but is that just to match the MPW version number? SUN C++ version 2.1 is by AT&T (*that* should be current but templates and exceptions are reserved words not yet implemented) and Borland just released 3.0 (which has templates and exceptions). >What's the story on the Mac? Does Apple or Zortech support templates and/or exceptions yet? Zortech C++ 3.1 is AT&T 2.0 with some 2.1. Unfortunately templates are not one of the 2.1 extentions. > * Origin: Quis custodiet ipsos custodes? (1:109/70.950) - ------------------------- From: Thad.Humphries@p950.f70.n109.z1.FidoNet.Org (Thad Humphries) Subject: Mac C++ Date: 21 Feb 92 00:27:02 GMT MU> Apple's C++ 3.x is really just the version number matched to MPW. It is MU> actually based on CFront 2.1, I think. It doesn't support templates or MU> exceptions. I don't know about Zortech. Thanks! I was afraid of that. Maybe by THINK C++ (dream on)! MU> BTW, consider using the return key sometimes. It is probably located above MU> your MU> right shift key. My mail reader (MacWoof) has word wrap. I can't speak for how yours interperts that but I never heard of a problem. Fill me in and I'll pass it to the author, Craig Vaughan who lives in the area. * Origin: Quis custodiet ipsos custodes? (1:109/70.950) - ------------------------- From: mlanett@void.ncsa.uiuc.edu (Mark Lanett) Subject: Mac C++ Organization: University of Illinois at Urbana Date: Sat, 22 Feb 1992 05:40:50 GMT Thad.Humphries@p950.f70.n109.z1.FidoNet.Org (Thad Humphries) writes: >My mail reader (MacWoof) has word wrap. I can't speak for how yours interperts that but I never heard of a problem. Fill me in and I'll pass it to the author, Craig Vaughan who lives in the area. Your mail reader may have word wrap but a lot of gui-dead unix machines don't. -- Mark Lanett mlanett@uiuc.edu Software Tools Group, NCSA, University of Illinois at Urbana-Champaign - ------------------------- From: lsr@apple.com (Larry Rosenstein) Subject: Mac C++ Date: 25 Feb 92 02:44:44 GMT In article <NEERI.92Feb20111512@iis.ethz.ch>, neeri@iis.ethz.ch (Matthias Ulrich Neeracher) writes: > > Apple's C++ 3.x is really just the version number matched to MPW. It is > actually based on CFront 2.1, I think. It doesn't support templates or > exceptions. I don't know about Zortech. I believe that MPW C++ 3.2 is based on AT&T CFront 2.1, and MPW C++ 3.1 is based on AT&T CFront 2.0. In addition to bug fixes there are some differences in the way nested types are handled between the 2 versions. CFront 3.0 is the AT&T version that supports templates, but not exceptions. -- Larry Rosenstein lsr@apple.com --------------------------- From: Daryl_Spitzer@mindlink.bc.ca (Daryl Spitzer) Subject: copying a resource Date: 20 Feb 92 20:59:11 GMT Organization: MIND LINK! - British Columbia, Canada How can I copy a single resource from one file to another? In particular, I want to my application to copy a resource (vers) from itself to a data file. I've tried this code, with no luck: CreateResFile( reply->fName ); resRefNum = HOpenResFile( reply->vRefNum, reply->vRefNum, reply->fName, fsWrPerm ); ChangedResource( applicationVersion ); WriteResource( applicationVersion ); CloseResFile( resRefNum ); Any hints? -- - ----------------------------------------------------------------- Daryl_Spitzer@mindlink.bc.ca "Life isn't just, life just is." a2251@mindlink.bc.ca -- Me (I think.) Spitzer@UNCAMULT.BITNET - ----------------------------------------------------------------- - ------------------------- From: colin@Cayman.COM (Colin "Atilla" Steele) Subject: copying a resource Date: 21 Feb 92 05:35:35 GMT Organization: Cayman Systems Inc., Cambridge, MA In article <10192@mindlink.bc.ca> Daryl_Spitzer@mindlink.bc.ca (Daryl Spitzer) writes: How can I copy a single resource from one file to another? This is off of the top of my head, but it should go something like this. Call Getresource to get a handle to the resource. DetachResource to remove it from the resource map. Lock the handle, then dup it, then DisposHandle it. Close the resource file from which the original was taken, and open the target resource file. Take the duped handle and call Addresource on it - this puts in back into the resource map. Now, when you close the target resource file, the resource will be put into it. This probably ain't 100% right, but it's close - it's too late to be doing this, but, oh, well :-) -- - ---------------------------------------------------------------------------- Colin Steele | Cayman Systems, 26 Landsdowne St., Cambridge, MA 02139 colin@cayman.com | (617) 494-1916 x209 | applelink D0523 | Fax (617) 494-9270 - ------------------------- From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy) Subject: copying a resource Date: 21 Feb 92 15:55:57 GMT Organization: Kalamazoo College colin@Cayman.COM (Colin "Atilla" Steele) writes: >Daryl_Spitzer@mindlink.bc.ca (Daryl Spitzer) writes: >> >>How can I copy a single resource from one file to another? > >Call Getresource to get a handle to the resource. DetachResource to >remove it from the resource map. Lock the handle, then dup it, then >DisposHandle it. Close the resource file from which the original was >taken, and open the target resource file. Take the duped handle and >call Addresource on it - this puts in back into the resource map. >Now, when you close the target resource file, the resource will be put >into it. There's a few unnecessary steps in there. AddResource() works on any old handle, but dies for resources. But DetachResource() turns a resource into just a regular handle. So, assuming both files are open already: UseResFile(sourceResFileID); h = Get1Resource(sourceType, sourceID); // h is a resource DetachResource(h); // h is now just a plain ol' handle UseResFile(destResFileID); AddResource(h, destType, destID, destName); // h is again a resource ...and then close the files, if you like. -- Jamie McCarthy Internet: k044477@kzoo.edu AppleLink: j.mccarthy Kzoo randomly kills all my mail; if I don't acknowledge, try resending. - ------------------------- From: scott@mcl.mcl.ucsb.edu (Scott Bronson) Subject: copying a resource Date: 23 Feb 92 02:24:27 GMT When you go to copy the resource attributes, you may run into a stupid little logical bug that is hard to find because of its indirect results. Consider this code (kindly taken from Jamie's previous post): Sorry if I prototyped the Set and GetResAttrs functions wrong--I'm at school now and my IMs are at home. UseResFile(sourceResFileID); h = Get1Resource(sourceType, sourceID); // h is a resource attrs = GetResAttrs(sourceType, sourceID); DetachResource(h); // h is now just a plain ol' handle UseResFile(destResFileID); AddResource(h, destType, destID, destName); // h is again a resource SetResAttrs(destType, destID, attrs); And you are done, right? Imagine my surprise when so simple a piece of code completely failed to save any resources to the file. It didn't bomb or ResErr -- it just didn't do anything. Here's the duh part. SetResAttrs resets the ResChanged attribute, and without ResChanged, it won't be written out when the file is closed. No amount of tracing through the file manager routines found this for me. :-) Put this right before SetResAttrs: attrs |= ResChanged; and you'll be okay. Hope this saves you some time! - Scott - ------------------------- From: mxmora@unix.SRI.COM (Matt Mora) Subject: copying a resource Date: 21 Feb 92 16:46:29 GMT Organization: SRI International, Menlo Park, California In article <10192@mindlink.bc.ca> Daryl_Spitzer@mindlink.bc.ca (Daryl Spitzer) writes: >How can I copy a single resource from one file to another? > >In particular, I want to my application to copy a resource (vers) >from itself to a data file. I've tried this code, with no luck: > > CreateResFile( reply->fName ); > resRefNum = HOpenResFile( reply->vRefNum, reply->vRefNum, > reply->fName, fsWrPerm ); > ChangedResource( applicationVersion ); > WriteResource( applicationVersion ); > CloseResFile( resRefNum ); > >Any hints? Well here's some pseudo code: fromrefNum=OpenResFile(fromfile); torefNum=OpenResFile(tofile); UseResFile(fromrefNum); myreshandle=Get1Resource(rType, id); DetachResource(myreshandle); UseResFile(torefNum); /* very important to check and see if the resources you are adding does not already exist. if it does, read it in and delete it before you add the new one. Addres does not check to see if a resource with the same id is already there. it blindly adds it. */ AddResource(myreshandle, rType, id, name); /* remember that the handle you pass addresource BECOMES a resource handle.*/ ChangedResource(myreshandle); UpdateResFile(torefNum); -- ___________________________________________________________ Matthew Mora | my Mac Matt_Mora@sri.com SRI International | my unix mxmora@unix.sri.com ___________________________________________________________ - ------------------------- From: REEKES@applelink.apple.com (Jim Reekes) Subject: copying a resource Date: 25 Feb 92 00:13:11 GMT Organization: Apple Computer, Inc. In article <COLIN.92Feb21003535@wrangel.Cayman.COM>, colin@Cayman.COM (Colin "Atilla" Steele) writes: > > In article <10192@mindlink.bc.ca> Daryl_Spitzer@mindlink.bc.ca (Daryl Spitzer) writes: > > How can I copy a single resource from one file to another? > > This is off of the top of my head, but it should go something like this. > > Call Getresource to get a handle to the resource. DetachResource to > remove it from the resource map. Lock the handle, then dup it, then > DisposHandle it. Close the resource file from which the original was > taken, and open the target resource file. Take the duped handle and > call Addresource on it - this puts in back into the resource map. > Now, when you close the target resource file, the resource will be put > into it. It's easier than that. Get the original resource and detach it. Then make sure the new targer file is the current resource file using UseResFile. Then call AddResource and UpdateResFile. - ----------------------------------------------------------------- Jim Reekes, E.O. | Macintosh Toolbox Engineering | Sound Manager Expert Apple Computer, Inc. | All opinions expressed are mine, and 20525 Mariani Ave. MS: 81-EQ | do not necessarily represent those Cupertino, CA 95014 | of my employer, Apple Computer Inc. - ------------------------- From: d88-jwa@byse.nada.kth.se (Jon W{tte) Subject: copying a resource Date: 27 Feb 92 21:16:07 GMT Organization: Royal Institute of Technology, Stockholm, Sweden > REEKES@applelink.apple.com (Jim Reekes) writes: It's easier than that. Get the original resource and detach it. Then make sure the new targer file is the current resource file using UseResFile. Then call AddResource and UpdateResFile. You might also want to call GetResAttrs before DetachResource and SetResAttrs on the new resource - but remember to call WriteResource BEFORE that, or the resChanged attribute will be zapped. -- This Signature is distributed under the conditions of the Signature License, available at a fee from h+@nada.kth.se (Jon W{tte) Reading the Signature implies that you accept to be bound by the terms in said License. Should you not agree on any of these terms, you must return the Signature unread to me. - ------------------------- From: mxmora@unix.SRI.COM (Matt Mora) Subject: copying a resource Date: 28 Feb 92 00:13:59 GMT Organization: SRI International, Menlo Park, California In article <20729@goofy.Apple.COM> REEKES@applelink.apple.com (Jim Reekes) writes: > >It's easier than that. Get the original resource and detach it. Then >make sure the new targer file is the current resource file using UseResFile. >Then call AddResource and UpdateResFile. Don't forget tho check the destination resource fork and make sure the resource id that your are adding doesn't already exist. Addresource\ does not check and will blindly add as many copies as you want. Been burned by this. Matt -- ___________________________________________________________ Matthew Mora | my Mac Matt_Mora@sri.com SRI International | my unix mxmora@unix.sri.com ___________________________________________________________ --------------------------- From: rcs91900@zach.fit.edu Charles Stockman Subject: How do you get SFGetFile() to show *.sic only Date: 20 Feb 92 23:40:44 GMT Organization: Florida Institute of Technology, ACS, Melbourne, FL Hello I am wondering, how would you tell SFGetFile() (macs built in directory requestor) that you only want to show files with the extension .sic Thanks a lot - ------------------------- From: mcmath@csb1.nlm.nih.gov (Chuck McMath) Subject: How do you get SFGetFile() to show *.sic only Date: 21 Feb 92 12:40:41 GMT Organization: MSD In article <3555@winnie.fit.edu>, rcs91900@zach.fit.edu Charles Stockman writes: > > Hello > > I am wondering, how would you tell SFGetFile() (macs built in directory > requestor) that you only want to show files with the extension .sic > > Thanks a lot > > I assume you are programming something, 'cuz if you want some off-the-shelf application to do this it ain't gonna work! :) One parameter to SFGetFile is the fileFilter; it's a ProcPtr. If this is not NIL, then that routine gets called for each file that is a candidate to be displayed. Your file filter should look at the name of the file and decide if the file should be displayed. Check Inside Mac volume I-523 and around there for more info. Hope this helps. chuck --chuck mcmath- mcmath@csb1.nlm.nih.gov MSD, Inc. * National Library of Medicine * National Institutes of Health Bethesda, MD 20894 - ------------------------- From: ABSURD@applelink.apple.com (Tim Dierks, ToyMeister, Cray abuser) Subject: How do you get SFGetFile() to show *.sic only Date: 26 Feb 92 19:29:52 GMT Organization: MacDTS, Apple Computer In article <3555@winnie.fit.edu>, rcs91900@zach.fit.edu Charles Stockman writes: > > Hello > > I am wondering, how would you tell SFGetFile() (macs built in directory > requestor) that you only want to show files with the extension .sic > > Thanks a lot [ If you're already familiar with all this, forgive me. ] The first thing is that on the Mac, filename extensions are generally not used to identify files. Users do not expect that your program will require them to name their files in any particular way, and you shouldn't require them to. Instead, the Mac uses file types, identifiers invisible to the user to identify file formats and contents. For example, a raw text file is usually of type 'TEXT' and a MacPaint file is of type 'MPNT'. These types are used to filter files in SFGetFile. However, if you need to do this, you can do it with a file filter function. Just write the function to exclude all files without the right name format. See Inside Mac, vol I pg 524 for more info. Tim Dierks MacDTS, but I speak for myself --------------------------- From: tamukha@sisters.cs.uoregon.edu (Tanka R. Sunuwar) Subject: How to store data record in file that grows dynamically? Organization: University of Oregon Computer and Information Sciences Dept. Date: Sat, 22 Feb 1992 09:23:58 GMT Hello Mac Gurus, May be this is too much to ask, but I am going to ask anyway. I am writing a program. It basically stores information about customers and associated transactions. Since, the list of data is going to be impossible to store in the RAM, I just store the keys in RAM and read only the necessary record from the disk and write it back. I have no problem with fixed size data. However, I also need to attatch a TEHandle (mac's text handler). Here goes the problem: I don't want to write whole 32K of TEHandle where actual data is less than 32K. ......|--.-----|--.---------------|--.---|.... rec#20 rec#21 rec#22 ..... in the disk. Now I want read rec#20, modify it and write it back. But, when I modify data block increases |--.--------------------------------| (looks like this) Now how would I go about writing back rec#2 at the same place in disk without messing up rec#21. This is like TEXT FIELD in HyperCard, TEXT field in 4th Dimension. If anybody out there have any idea, suggestion, or ftp sites where I could get some examples of this kind, I really appreciate it. BTW, I am using THINK C 5.0.2 with TCL. Many thanks in advance. - ------------------------- From: emmayche@msgate.corp.apple.com (Mark Hartman) Subject: How to store data record in file that grows dynamically? Date: 26 Feb 92 18:56:40 GMT Organization: Organization? Who's organized? In article <1992Feb22.092358.2634@cs.uoregon.edu>, tamukha@sisters.cs.uoregon.edu (Tanka R. Sunuwar) writes: > > Maybe this is too much to ask, but I am going to ask anyway. I am writing > a program. It basically stores information about customers and associated > transactions. Since, the list of data is going to be impossible to store > in the RAM, I just store the keys in RAM and read only the necessary record > from the disk and write it back. I have no problem with fixed size data. > However, I also need to attatch a TEHandle (mac's text handler). Here goes > the problem: I don't want to write whole 32K of TEHandle where actual data > is less than 32K. > > ......|--.-----|--.---------------|--.---|.... > rec#20 rec#21 rec#22 ..... in the disk. > Now I want read rec#20, modify it and write it back. But, when I modify > data block increases |--.--------------------------------| (looks like this) > Now how would I go about writing back rec#20 at the same place in disk > without messing up rec#21. There are several ways to accomplish this, and it depends upon some other considerations: 1) Do you want to be able to cancel a group of transactions? 2) Are many people going to be permitted to use the file at the same time? To answer your last question first, there's really no practical way to write the record back to the same physical spot without messing up not only record 21, but ALL subsequent records. Obviously, since other programs seem to do this, there must be a way to make it APPEAR as though it's in the same physical place. If you want to directly update the file, and only one person will use the file at a time, and there's no "undo" capability needed (except one level), I suggest that you set up the file with a structure similar to the following (each division is 4 bytes): Allocation information blocks (first one starts at byte 0 in file): +----------- | 'ALOC' in ASCII +----------- | Size in bytes of this block (all data including required trailing zero; | (size-16)/4 = n (count of records covered by this block)) +----------- | File address (byte) of start of next allocation block, 0 if no more +----------- | File address (byte) of record 1 +----------- | . . . +----------- | File address (byte) of record n +----------- | 0 (required to signal end of block, in case of corruption) +----------- Data blocks: +----------- | 'DATA' in ASCII +----------- | Size in bytes of this block (all data including required trailing zero) +----------- | All data block information goes here (not limited to 4 bytes) +----------- | 0 (required to signal end of block) +----------- Free blocks: +----------- | 'FREE' in ASCII +----------- | Size in bytes of this block (all data including required trailing zero) +----------- | Free space +----------- | 0 (required to signal end of block) +----------- Using this scheme, you would simply allocate a new data block at the end of the file, write your information there, mark the old data as 'FREE', and update the pointer in the allocation block to point to your new data block. In your program's exit routine, you would traverse the 'ALOC' blocks and gather them into one large 'ALOC' block in a new file (leaving some room for expansion, as you desire), then copy the information from the old file into the new file in a compact form, leaving out the 'FREE' blocks completely. The overhead of this method is 16 bytes per record, plus 16 bytes for each allocation block, which is relatively a lot, but it's a very easy structure to implement. Additionally, all the records will appear to be in physical order if you access the records via the 'ALOC' pointer blocks. This structure also has a LOT of expansion potential if you so desire. If this doesn't do it for you, please e-mail me with your specific problems with it and I'll try to answer them. Mark Hartman, N6BMO emmayche@msgate.corp.apple.com --------------------------- End of C.S.M.P. Digest **********************